// store/design.ts
import { defineStore } from 'pinia';
import useUserStore from '@/store/modules/user';

const userStore = useUserStore();

interface DesignState {
  nodeMap: Map<any, any>;
  formItemMap: Map<any, any>;
  isEdit: boolean | null;
  loginUser: Record<string, any>;
  selectedNode: Record<string, any>;
  selectFormItem: any | null;
  design: Record<string, any>;
}

export const useDesignStore = defineStore('design', {
  state: (): DesignState => ({
    nodeMap: new Map(),
    formItemMap: new Map(),
    isEdit: null,
    loginUser: userStore || {},
    selectedNode: {},
    selectFormItem: null,
    design: {}
  }),
  actions: {
    setSelectedNode(val: any) {
      this.selectedNode = val;
    },
    loadForm(val: any) {
      this.design = val;
    },
    setIsEdit(val: boolean | null) {
      this.isEdit = val;
    },
    setDesignFormConfig(val: any) {
      this.design.formConfig = val;
    },
    setDesignFormItems(val: any) {
      this.design.formItems = val;
    }
  },
  getters: {
    getLoginUser: (state) => state.loginUser,
    isEdit: (state) => state.isEdit
  }
});
